<%@page import="dashboard.User"%>
<!DOCTYPE html>
<html>

<head>
<title>Favorites</title>
<link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />

</head>

<body>
<div id="main">
<%@include file="header.jsp" %>


<%
User tussenUser = (User) session.getAttribute("user");
if(tussenUser==null){
	response.sendRedirect("login.jsp");
}
else{
currentUser = UserRegistry.getInstance().getUser(tussenUser.getUserName());
if (request.getParameter("action")==null){
%>
<fieldset>
			<legend> Favorites </legend>
			
	<br>
	<div  class="button" style="z-index: 25; position:relative;">
	<form name="toevoegen" method="post" action="Favorites.jsp?action=add">
	<input style="width: 100%;" type="submit" value="Add favorite">
	</form>

	<form name="bekijken" method="get" action="Favourites">
	<input name="action" value="view" type="hidden">
	<input style="width: 100%;" type="submit" value="View favorites">
	</form>
	<br>
	<form name="terug" method="post" action="dashboard.jsp">
	<input  type="submit" value="Back" onclick="dashboard.jsp">
	</form>
	</div>
	
	</fieldset>
<%
}
else 
if(request.getParameter("action").equals("add")){ 
%>
<fieldset><legend>Add a Favorite</legend>
	<p style="font-size: 25px;">Search for a friend:</p>
	<form method="post" action="Search" class="button" >
	<input type="text" name="SearchQuerry" style="width: 100%; height: 33px; font-size: 25px;" >
	<br>
	<br>
	<input " type="submit" value="Continue" onclick="" style="width: 100%;">
	</form>
	
	<br>
	<form class="button" method="post" action="Favorites.jsp">
		<input type="submit" value="Back">
	</form>
	</fieldset>
<%
}
else 
if(request.getParameter("action").equals("view")){ 
%>
<fieldset><legend>Your Favorites</legend>
	<table class='tablesorter' id='LinkTable' width='97%'>
			<thead>
				<tr>
					<th colspan="1">UserName</th> 
					<th colspan='1'>FirstName</th>
					<th colspan='1'>Name</th>
					<th colspan='1'>Rnumber</th>
					<th colspan='1'>Stats</th>
				</tr>
			</thead>
	<tbody>
	<%
	List<User> favorites = (List<User>) session.getAttribute("fav");
	if(favorites==null){
		%><tr>
		<td style="font-size:25px; text-align: center;"> You have no favorites.</td></tr>
		<%
	}
	else{	
	for(User u: favorites)
	{
		
		%> 
		<tr>
		<td>
			<%=u.getUserName()%>
		</td>
		
		<td>
			<%=u.getFirstName()%>	
		</td>
		<td>
			<%=u.getName()%>	
		</td>
		<td>
			<%=u.getNumber()%>	
		</td>
		<td class="tb3" style="text-align: center;" onclick="window.location='Statistics?rNumber=<%=u.getNumber()%>'">
		View Stats
		</td>
		<td width="24">
			<a href="Favourites?action=removefav&&userName=<%=u.getUserName()%>"><img src="img/cross.png" width="24" height="24" style="cursor: pointer;" title="Remove from favourites"></a>
		</td>
		</tr>
		<%
	}}
	
	%>
	</tbody>
	</table>
	
	<br>
	<form class="button" method="post" action="Favorites.jsp">
		<input type="submit" value="Back">
	</form>
	</fieldset>
<%
}
else
if(request.getParameter("action").equals("searchresults")){ 
	%>
	<fieldset><legend>Add Favorite</legend>
	<table class='tablesorter' id='LinkTable' width='97%'>
			<thead>
				<tr>
					<th colspan="1">UserName</th> 
					<th colspan='1'>FirstName</th>
					<th colspan='1'>Name</th>
					<th colspan='1'>Rnumber</th>
				</tr>
			</thead>
	<tbody>
	<%
	List<User> results = (List<User>) session.getAttribute("SearchResults");
	if(results.size() == 0){%>
		<td style="font-size:25px; text-align: center;"> No users were found.</td>
	<% } 
	for(User u: results)
	{
		%> 
		<tr>
		<td>
			<%=u.getUserName()%>
		</td>
		
		<td>
			<%=u.getFirstName()%>	
		</td>
		<td>
			<%=u.getName()%>	
		</td>
		<td>
			<%=u.getNumber()%>	
		</td>
		<td width="24">
			<a href="Favourites?action=addfav&&userName=<%=u.getUserName()%>"><img src="img/add-icon.png" width="24" height="24" style="cursor: pointer;" title="Add to favourites"></a>
		</td>
		</tr>
		<%
	}
	%>
	</tbody>
	</table>
	
	<br>
	<form class="button" method="post" action="Favorites.jsp?action=add">
		<input type="submit" value="Back">
	</form>
	</fieldset>
	<%
}}

%>
</div>

</body>
</html>